﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ggprot
{
    class ImgReply
    {
        private byte totalLength;

        private byte flag;
        private int size;
        private int crc32;
        private string fileName;
        private byte[] image;

        public byte Flag
        {
            get { return flag; }
            set { flag = value; }
        }

        public int Size
        {
            get { return size; }
            set { size = value; }
        }

        public int Crc32
        {
            get { return crc32; }
            set { crc32 = value; }
        }

        public string FileName
        {
            get { return fileName; }
            set { fileName = value; }
        }

        public byte[] Image
        {
            get { return image; }
            set { image = value; }
        }

        public byte TotalLength
        {
            get { return totalLength; }
            set { totalLength = value; }
        }

        public void ReadBytes(byte[] bytes)
        {
            flag = bytes[1];
            size = BitConverter.ToInt32(bytes, 1);
            crc32 = BitConverter.ToInt32(bytes, 5);
            if (flag == (int)MessageAttribs.ImageReplyFirst)
                fileName = BitConverter.ToString(bytes, 9, 19);
            image = new byte[bytes.Length - 28];
            Array.Copy(bytes, 28, image, 0, image.Length);
        }
    }
}
